package lesson7.pages;


import org.openqa.selenium.By;
import org.testng.Assert;


/**
 * Created with IntelliJ IDEA.
 * User: alisa
 * Date: 29.03.14
 * Time: 15:24
 * To change this template use File | Settings | File Templates.
 */
public class RegistrationPage extends BasePage {
    protected String registrationAddress = "http://my.rozetka.com.ua/signup/";
    protected By fieldName = By.xpath("/html/body/div[1]/div/div/div[2]/div/div/div[2]/div/form/div[1]/input");
    protected By fieldEmail = By.xpath("/html/body/div[1]/div/div/div[2]/div/div/div[2]/div/form/div[2]/input");
    protected By fieldPassword = By.xpath("/html/body/div[1]/div/div/div[2]/div/div/div[2]/div/form/div[3]/input");
    protected By registrationButton = By.xpath("/html/body/div[1]/div/div/div[2]/div/div/div[2]/div/form/div[6]/button");
    protected By personalPage = By.xpath(".//span[contains(text(),'Личный кабинет')]");

    protected RegistrationPage() {
        super(driver);
    }

    @Override
    protected void openPage() {
        driver.get(registrationAddress);
        Assert.assertEquals(driver.getCurrentUrl(), registrationAddress);
    }


    public void fillAndSubmitRegistrationForm(CharSequence testName,
                                              CharSequence testEmail,
                                              CharSequence testPassword) {

        driver.findElement(fieldName).sendKeys(testName);
        driver.findElement(fieldEmail).sendKeys(testEmail);
        driver.findElement(fieldPassword).sendKeys(testPassword);
        driver.findElement(registrationButton).click();

    }

    public void verifySuccessfulRegistration() {
        driver.findElements(personalPage);
    }

    public void verifyUnsuccessfulRegistration() {
        String windowHandler = driver.getWindowHandle();
        driver.switchTo().window(windowHandler);
    }

    protected long generateSuffixToEmail() {
        return System.currentTimeMillis();
    }
}
